


public abstract class Individual implements Comparable,Replicable,Variable {
	protected  double fitness;
	protected static final double  idealFitness=0.01;
	
/**
	 * Construct a new default Individual.  The default  Individual
	 * has fitness=-1.
	 */	
	
public Individual(){
		this.fitness=-1;
}
/**
	 * returns the fitness only only if computes fitness at most once during object life time
	 *@returns fitness
	 */				
	
public double getFitness(){
		if(this.fitness==-1){
			fitness=this.evaluate();
		}
			
		return this.fitness;
}
/**
 */

protected abstract double evaluate();


/**
	 * returns whatever the individual is ideal
	 *i.e has the best possible fitness
	 *@returns if the individual is ideal
	 */				
public boolean isIdeal(){
	return (this.fitness>=0&this.fitness<=idealFitness);
}
public int compareTo(Object obj){
	if(!(obj instanceof Individual)){
		throw new RuntimeException(
			"compare to get a non Individual paramter");
	}
	return ((int)(this.getFitness()- ((Individual)obj).getFitness()));
				
}

public Object replicate(){
	Individual ans=this.copy();
	ans.fitness=-1;
	return ans;	
}	


protected abstract Individual copy();

protected abstract void initGenome();


}